<?php

namespace addons\wwh\controller;

use think\Request;

class Base extends \think\addons\Controller
{
    // 初始化
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $config = get_addon_config('wwh');
        // 设定主题模板目录
        $this->view->engine->config('view_path', $this->view->engine->config('view_path') . $config['theme'] . DS);
        $this->view->engine->config('taglib_pre_load', 'addons\wwh\taglib\Wwh');
    }

    public function _initialize()
    {
        parent::_initialize();
        // 如果请求参数action的值为一个方法名,则直接调用
        $action = $this->request->post("action");
        if ($action && $this->request->isPost()) {
            return $this->$action();
        }

        $this->view->assign('nav', \addons\wwh\model\Column::getNav());
        $this->view->assign('navId', \addons\wwh\model\Column::where(['status'=>'normal'])->column('*','id'));
        $this->view->assign('service', \addons\wwh\model\Archives::getService());
        $this->view->assign('about', \addons\wwh\model\Archives::getAbout());
        $this->view->assign('contact', \addons\wwh\model\Archives::getContact());
        $this->view->assign('config', \addons\wwh\model\Archives::getConfig());
    }

}
